package com.zhixue.content.controller;

import com.zhixue.content.model.dto.CoursePreviewDto;
import com.zhixue.content.model.po.CoursePublish;
import com.zhixue.content.service.CoursePublishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Auther: 李 力
 * @Date: 2025/4/30
 * @Description: com.zhixue.content.controller
 * @version: 1.0
 */
@Controller
public class CoursePublishController {

    @Autowired
    private CoursePublishService coursePublishService;

    @GetMapping("/coursepreview/{courseId}")
    public ModelAndView preview(@PathVariable Long courseId) {
        ModelAndView modelAndView = new ModelAndView();
        CoursePreviewDto coursePreviewInfo = coursePublishService.getCoursePreviewInfo(courseId);
        modelAndView.addObject("model", coursePreviewInfo);
        modelAndView.setViewName("course_template");
        return modelAndView;
    }

    //提交审核
    @ResponseBody
    @PostMapping("/courseaudit/commit/{courseId}")
    public void commitAudit(@PathVariable("courseId") Long courseId) {
        //todo 机构ID，暂时写死
        Long companyId = 1L;
        coursePublishService.commitAudit(companyId, courseId);
    }

    //课程发布
    @ResponseBody
    @PostMapping("/coursepublish/{courseId}")
    public void coursepublish(@PathVariable("courseId") Long courseId) {
        //todo 机构ID，暂时写死
        Long companyId = 1L;
        coursePublishService.publish(companyId, courseId);
    }

    //查询课程发布信息
    @ResponseBody
    @GetMapping("/r/coursepublish/{courseId}")
    public CoursePublish getCoursepublish(@PathVariable("courseId") Long courseId) {
        return coursePublishService.getCoursePublish(courseId);
    }
}
